﻿@using LanDBom.Models
@{
    ViewBag.Title = "Material_inquiry";
}

@section styles{
    <style>
        th {
            text-align: center;
        }
        td {
            text-align: center;
        }
        #bigdiv {
            overflow: scroll;
            margin-left: 15px;
            height: 450px;
        }
        table {
            width: 100%;
        }
    </style>
}
<from>
    <fieldset>
        <label id="HJ_CP_sqd" class="len">物料询价</label>
        <div id="B_TJCG">提交</div>
        <div id="B_ZBHJ">开始回价</div>
        <div id="bigdiv">
            <table>
                <thead>
                    <tr>
                        <th><input type="checkbox" /></th>
                        <th>物料名称</th>
                        <th>料号</th>
                        <th>生效日期</th>
                        <th>失效日期</th>
                        <th>当前供应商</th>
                        <th>当前价格</th>
                        <th>询价供应商</th>
                    </tr>
                </thead>
                <tbody id="XJ_CL_TB">
                </tbody>
            </table>
        </div>
    </fieldset>
</from>


@section scripts
{
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>
    <script>
        $(function () {
            get_nda()
            Commit_database()

            function get_nda() {
                $.ajax({
                    url: '/Procure/Material_inquiry',
                    type: 'GET',
                    data: {"state": 1 },
                    success: function (data) {
                        createTR(data);
                    },
                    error: function () {
                        alert('Request Error');
                    }
                })
            }
            function createTR(data) {
                $('#XJ_CL_TB tr').remove();
                $.each(data, function (i, item) {
                    var $tr = $(`
                            <tr>
                                <td><input type="checkbox"/></td>
                                <td id="XJ_CL_WL_z1">${item.FM_name}</td>
                                <td id="XJ_CL_LH_z1">${item.FM_bai}</td>
                                <td>${item.Nd_shengxiao}</td>
                                <td>${item.Nd_shixiao}</td>
                                <td>${item.Nd_Gong}</td>
                                <td>${item.Nd_jiage}</td>
                                <td id="XJ_CP_Gong_z1">
                                    <select name="CL_name" class="form-control" id="txtfu">
                                        <option>--请选择--</option>
                                        @foreach (var item in ViewBag.listAgys as List<Providers>)
                                        {
                                            <option value="@item.PR_name" id="CL_ID">@item.PR_name</option>
                                        }
                                    </select>
                                </td>
                            </tr>

                        `);
                    $('#XJ_CL_TB').append($tr);
                })
            }

            function Commit_database() {
                $("#B_TJCG").click(function () {
                    var CG_XX = [];
                    var check = $("input[type=checkbox]:checked").parent().parent().length;
                    if (check < 0) {
                        alert(0);
                    }
                    else {
                        $("input[type=checkbox]:checked").parent().parent().each(function (index, obj) {
                            CG_XX.push({
                                Inf_shen:"物料询价",
                                Inf_wu: $("td[id='XJ_CL_WL_z1']", obj).text(),
                                Inf_liao: $("td[id='XJ_CL_LH_z1']", obj).text(),
                                Inf_gong: $("select[id='txtfu']", obj).val(),
                                Inf_zhuang: "等待中"

                            })
                            console.log("共" + CG_XX.length + "数据");
                            console.log(CG_XX);
                        })
                        //发出请求
                        $.ajax({
                            url: "/Procure/AddCGXX_CL",
                            type: 'POST',
                            data: JSON.stringify(CG_XX),
                            contentType: "application/json;charset=utf-8",
                            dataType: "json",
                            success: function (text) {
                                if (text > 0) {
                                    alert("添加成功" + text.msg);
                                    
                                } else {
                                    alert("添加失败" + text.msg);
                                }

                            },
                            error: function (text) {
                                alert("系统错误" + text);
                            }
                        })
                    }

                })
            }
            $(document).on("click", "#B_ZBHJ", function () {
                window.location.href = "/Procure/Material_rebate"
            })
        })
    </script>
}